package com.example.pei.ithinklearnt.view.customview;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;

import com.example.pei.ithinklearnt.R;

/**
 * Created by Pei on 2017/12/19.
 */

public class CommentSelectedDialog extends Dialog implements View.OnClickListener{
    private Context mContext;
    private Button button_reply;
    private Button button_copy;
    private Button button_delete;
    private CommentSelectedDialogListener mListener;

    private int  permission;   // 0 代表不是自己，有回复 没删除   1代表自己发的评论，有删除 没回复

    public interface CommentSelectedDialogListener{
        void onClick(View v);
    }

    public CommentSelectedDialog(@NonNull Context context) {
        super(context);
        this.mContext=context;
    }

    public CommentSelectedDialog(@NonNull Context context, int themeResId,int  permission,CommentSelectedDialogListener listener) {
        super(context, themeResId);
        this.mContext=context;
        this.mListener=listener;
        this.permission=permission;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.comment_selected_dialog);

        button_reply=findViewById(R.id.btn_reply);
        button_copy=findViewById(R.id.btn_copy);
        button_delete=findViewById(R.id.btn_del);

        button_reply.setOnClickListener(this);
        button_copy.setOnClickListener(this);
        button_delete.setOnClickListener(this);

        if(permission==0){
            //0 代表不是自己，有回复 没删除
            findViewById(R.id.tv_line2).setVisibility(View.GONE);
            button_delete.setVisibility(View.GONE);

            button_reply.setVisibility(View.VISIBLE);
            findViewById(R.id.tv_line1).setVisibility(View.VISIBLE);
            //最下方的复制重新设置样式
            button_reply.setBackgroundResource(R.drawable.button_bottom_selector);

        }else if(permission==1){
            //1代表自己发的评论，有删除 没回复
            findViewById(R.id.tv_line2).setVisibility(View.VISIBLE);
            button_delete.setVisibility(View.VISIBLE);

            button_reply.setVisibility(View.GONE);
            findViewById(R.id.tv_line1).setVisibility(View.GONE);

        }
    }

    @Override
    public void onClick(View view) {
        mListener.onClick(view);
    }
}
